package NC88_寻找第K大;

import java.util.*;

public class Solution {
    public int findKth(int[] a, int n, int K) {
        // write code here
        if (a == null || a.length < 1){
            return 0;
        }
        PriorityQueue<Integer> queue = new PriorityQueue<>(K);
        for (int num : a){
            if (queue.size() < K){
                queue.offer(num);
            }else {
                if (num > queue.peek()){
                    queue.poll();
                    queue.offer(num);
                }
            }
        }
        return queue.peek();
    }
}